﻿#region Usings

using System.Globalization;
using System.Text;
using System.Xml;

#endregion

namespace Kazkommertsbank.Framework.Model.Pay
{
    public class AppendixItem
    {
        public int Number { get; set; }
        public string Name { get; set; }
        public int Quantity { get; set; }
        public decimal Amount { get; set; }

        public string ToXmlString()
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = new ASCIIEncoding();
            settings.Indent = false;
            settings.OmitXmlDeclaration = true;

            StringBuilder result = new StringBuilder();
            using(XmlWriter writer = XmlWriter.Create(result, settings))
            {
                writer.WriteStartElement("item");
                writer.WriteAttributeString("number", Number.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("name", Name);
                writer.WriteAttributeString("quantity", Quantity.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("amount", Amount.ToString("0.00", CultureInfo.InvariantCulture));
                writer.WriteEndElement();
            }

            return result.ToString();
        }
    }
}